package com.itany.corejava.code14_lambda;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年12月15日 10:33
 */
public class 构造方法的引用 {
    public static void main(String[] args) {
        // 类名::new  构造方法引用
        Supplier<User> s1=new Supplier<User>() {
            @Override
            public User get() {
                return new User();
            }
        };

        Supplier<User> s2=()->new User();

        Supplier<User> s3=User::new;
        System.out.println(s3.get()+"----");

        Function<String,User> f1=new Function<String, User>() {
            @Override
            public User apply(String s) {
                return new User(s);
            }
        };

        Function<String,User> f2=s->new User(s);

        Function<String,User> f3=User::new;
        User user=f3.apply("alice");
        System.out.println(user);


        BiFunction<String,String,User> bf=new BiFunction<String, String, User>() {
            @Override
            public User apply(String username, String password) {
                return new User(username,password);
            }
        };

        BiFunction<String,String,User> bf2=(username,password)-> new User(username,password);
        BiFunction<String,String,User> bf3=User::new;
        User user2=bf3.apply("admin","123456");
        System.out.println(user2);

        // 内置的函数式接口中最多只能调用两个参数的构造，但是可以自定义


        AA<String,Stu> aa=new AA<String, Stu>() {
            @Override
            public Stu cal(String t1, String t2, String t3) {
                return new Stu(t1,t2,t3);
            }
        };
        AA<String,Stu> aa2=(t1,t2,t3)->new Stu(t1,t2,t3);

        AA<String,Stu> aa3=Stu::new;
        System.out.println(aa3.cal("huahua","123","南京"));







    }
}

interface AA<T,R>{
    R cal(T t1,T t2,T t3);
}